package vcp.client.reports;

import java.io.Serializable;

import org.joda.time.format.DateTimeFormat;

import vcp.entity.Complaint;
import vcp.entity.ComplaintHistory;
import vcp.entity.Customer;
import vcp.enums.ReportType;
/**
 * 
 * @author VCP team
 *<p> complaint report class</p>
 */
public class ComplaintsReport extends ReportAbstract
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 3057809893433557834L;

	/**
	 * Complaints report constructor
	 */
	public ComplaintsReport ()
	{
		super(ReportType.COMPLAINTS);
	}

	// ****************************************************************************************************************************
	// Public method
	// ****************************************************************************************************************************
	/**
	 * adds new complaint
	 * @param complaint
	 * @param complaintHistory
	 * @param customer
	 */
	public void add ( Complaint complaint, ComplaintHistory complaintHistory, Customer customer )
	{
		ComplaintsRowWrapper complaintsRowWrapper = new ComplaintsRowWrapper();

		complaintsRowWrapper.setComplaintID(complaint.getID());
		complaintsRowWrapper.setCustomerName(customer.getUserFirstName() + " " + customer.getUserLastName());
		complaintsRowWrapper.setComplaintType(complaint.getType().toString());
		complaintsRowWrapper.setComplaintStatus(complaint.getStatus().toString());
		complaintsRowWrapper.setComplaintText(complaint.getText());
		complaintsRowWrapper.setComplaintResolveText(complaintHistory != null ? complaintHistory.getComplaintResolveText() : "");
		complaintsRowWrapper.setOpenDate(DateTimeFormat.forPattern("dd/MM/YYYY").print(complaint.getOpenDate()));
		complaintsRowWrapper.setCloseDate(complaintHistory != null ? DateTimeFormat.forPattern("dd/MM/YYYY").print(complaintHistory.getCloseDate()) : "");

		this.reportDataRow.add(complaintsRowWrapper);
	}

	// ****************************************************************************************************************************
	// ReportAbstract method
	// ****************************************************************************************************************************
	@Override
	public String[] getHeaders ()
	{
		return new String[]
				{ "Complaint ID",
				"Customer",
				"Complaint Type",
				"Text",
				"Resolve Text",
				"Open Date",
				"Close Date"};
	}

	// ****************************************************************************************************************************
	// Private class
	// ****************************************************************************************************************************
	/**
	 * 
	 * @author VCP team
	 *<p> complaint row wrapper class </P>
	 */

	private class ComplaintsRowWrapper implements Serializable, IWrapperConverter
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = - 5696353236593832481L;
		// ****************************************************************************************************************************
		// Setter-Getter class
		// ****************************************************************************************************************************
		private String complaintStatus;

		/**
		 * getter
		 * @return status
		 */
		public String getComplaintStatus()
		{
			return this.complaintStatus;
		}
		/**
		 * setter
		 * @param complaintStatus
		 */
		public void setComplaintStatus(String complaintStatus)
		{
			this.complaintStatus = complaintStatus;
		}

		private String closeDate;

		/**
		 * getter
		 * @return closure date
		 */
		public String getCloseDate()
		{
			return this.closeDate;
		}
		/**
		 * setter
		 * @param closeDate
		 */
		public void setCloseDate(String closeDate)
		{
			this.closeDate = closeDate;
		}

		private String openDate;
		/**
		 * getter
		 * @return open date
		 */
		public String getOpenDate ()
		{
			return this.openDate;
		}
		/**
		 * setter
		 * @param openDate
		 */
		public void setOpenDate ( String openDate )
		{
			this.openDate = openDate;
		}

		private String complaintResolveText;
		/**
		 * getter
		 * @return resolve text
		 */
		public String getComplaintResolveText ()
		{
			return this.complaintResolveText;
		}
		/**
		 * setter
		 * @param complaintResolveText
		 */
		public void setComplaintResolveText ( String complaintResolveText )
		{
			this.complaintResolveText = complaintResolveText;
		}

		private String complaintText;
		/**
		 * getter
		 * @return text
		 */
		public String getComplaintText ()
		{
			return this.complaintText;
		}
		/**
		 * setter
		 * @param complaintText
		 */
		public void setComplaintText ( String complaintText )
		{
			this.complaintText = complaintText;
		}

		private String complaintType;
		/**
		 * getter
		 * @return type
		 */
		public String getComplaintType ()
		{
			return this.complaintType;
		}
		/**
		 * setter
		 * @param complaintType
		 */
		public void setComplaintType ( String complaintType )
		{
			this.complaintType = complaintType;
		}

		private String customerName;
		/**
		 * Getter
		 * @return customer name
		 */
		public String getCustomerName ()
		{
			return this.customerName;
		}
		/**
		 * setter
		 * @param customerName
		 */
		public void setCustomerName ( String customerName )
		{
			this.customerName = customerName;
		}

		private Integer complaintID;
		/**
		 * getter
		 * @return complaint ID
		 */
		public Integer getComplaintID ()
		{
			return this.complaintID;
		}
		/**
		 * setter
		 * @param complaintID
		 */
		public void setComplaintID ( Integer complaintID )
		{
			this.complaintID = complaintID;
		}

		// ****************************************************************************************************************************
		// IWrapperConverter class
		// ****************************************************************************************************************************
		@Override
		public Object[] toObjectArray ()
		{
			return new Object[]
					{ this.getComplaintID()
					, this.getCustomerName()
					, this.getComplaintType()
					,this.getComplaintStatus()
					, this.getComplaintText()
					, this.getComplaintResolveText()
					, this.getOpenDate()
					,this.getCloseDate()};
		}

	}
}
